package gwtool.gui.components;

import java.util.Date;

import org.jdesktop.swingx.JXDatePicker;

public class JXDatePickerWithChangeSupport extends JXDatePicker implements ChangeSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5198408913872969458L;

	private Date oldDate = null;

	public JXDatePickerWithChangeSupport() {

		super();
	}

	public JXDatePickerWithChangeSupport(Date date) {

		super(date);
		this.oldDate = date;
	}

	@Override
	public boolean hasChanged() {

		if (oldDate == null && getDate() == null) {
			return false;
		}
		if (oldDate == null && getDate().getTime() != 0) {
			return true;
		}
		if (getDate() == null && oldDate != null) {
			return true;
		}
		if (getDate().getTime() == oldDate.getTime()) {
			return false;
		} else {
			return true;
		}
	}

	@Override
	public void setDate(Date date) {

		oldDate = date;
		super.setDate(date);
	}

	@Override
	public void setChangedFalse() {

		oldDate = getDate();
	}
}
